package com.example.demo.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.example.demo.entity.User;
import com.example.demo.entity.UserExample;
import com.example.demo.mapper.UserMapper;


@Service
public class UserServiceImpl implements UserService {


	@Autowired
	private UserMapper userMapper;



	// 保存User
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public Integer saveUser(User user) {
		// 添加回滚,增删改用REQUIRED，查用SUPPORTS
		return userMapper.insert(user);
	}

	// 查找所有User
	@Override
	public List<User> findAll() {
		// 正式业务逻辑
		List<User> userList = userMapper.selectByExample(null);
		return userList;
	}

	// 删除User
	@Override
	public Integer deleteUser(Integer id) {
		return userMapper.deleteByPrimaryKey(id);
	}

	// 通过id获得user
	@Override
	public User findById(Integer id) {
		return userMapper.selectByPrimaryKey(id);
	}

	// 修改User
	@Override
	public Integer updateUser(User user) {
		return userMapper.updateByPrimaryKeySelective(user);
	}

}
